package com.wanxi.config.security;

import com.wanxi.dao.ManagerDao;
import com.wanxi.model.Manager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

@Component("userDetailsService")
public class UserDetailsServiceConfig implements UserDetailsService {
    @Autowired
    ManagerDao managerDao;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Manager manager = managerDao.findByName(username);
        if(manager==null){
            throw new UsernameNotFoundException("the manager is not found!");
        }
        return manager;
//        return null;
    }
}
